#ifndef __BANK_H__
#define __BANK_H__

#include <cstdint>
#include "membackend/accurateTransaction.h"
#include "membackend/accurateCommand.h"
#include "membackend/accurateIRankTiming.h"

namespace NS_BANK {
    typedef enum State {
        OPEN = 0, 
        CLOSED, 
        SREF, 
        PD, 
        STATE_SIZE
    } BANK_STATE;
}

typedef struct expected_time{
    uint64_t activate_time; // 预期激活时间
    uint64_t precharge_time; // 预期预充电时间
    uint64_t rw_time; // 预期读写时间    
}expected_time;


class Bank{
public:
    NS_BANK::BANK_STATE state;

    uint64_t bank_id;
    uint64_t bankGroup_id;

    uint64_t last_row_id; // 最近访问的行ID
    uint64_t last_column_id; // 最近访问的列ID

    IRankTiming* rank_timing;
    expected_time expectedTime; // 预期时间

    Bank();
    int Init(uint64_t bankGroup_id, uint64_t bank_id, IRankTiming * rank_timing);
    void setState(NS_BANK::BANK_STATE state);
    NS_BANK::BANK_STATE getState();
    void setBankID(uint64_t bank_id);
    uint64_t getBankID();
    uint64_t Process(DRAMCommand &cmd, uint64_t time, const AddressMappingConfig *amp);
    bool isNeedPreCharge(uint64_t row_id, uint64_t time);
    bool isNeedActive(uint64_t row_id, uint64_t time);
    bool isNeedRW();
    uint64_t issuePrecharge(uint64_t time, const AddressMappingConfig *amp);
    uint64_t issueActive(uint64_t time, const AddressMappingConfig *amp);

    uint64_t issueRead(DRAMCommand &cmd, uint64_t time, const AddressMappingConfig *amp);
    uint64_t issueWrite(DRAMCommand &cmd, uint64_t time, const AddressMappingConfig *amp);

};



#endif